// FtpConnection.h: interface for the CFtpConnection class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_FTPCONNECTION_H__A0BE133E_25DB_4ED0_9C73_32CE06064EEB__INCLUDED_)
#define AFX_FTPCONNECTION_H__A0BE133E_25DB_4ED0_9C73_32CE06064EEB__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <wininet.h>
#pragma comment(lib, "wininet.lib")
#include "CommonDef.h"

class CFtpConnection  
{
private:
	CFtpConnection() : m_InternetSession(NULL)	{};
	virtual ~CFtpConnection(){};
public:

	static CFtpConnection * CreateInstance()
	{
		if (m_pInstance != NULL)
		{
			return m_pInstance;
		}
		else
		{
			m_pInstance = new CFtpConnection();
			return m_pInstance;
		}
	}

	void DestroyInstance()
	{
		delete m_pInstance;
		m_pInstance = NULL;
	}

	BOOL FtpSession();
	BOOL FtpClose();

	BOOL FtpConnect(IN const CString & strServer,	IN const CString & strUsername, 
					IN const CString & strPassword,	IN const int nPort = INTERNET_DEFAULT_FTP_PORT);
	BOOL FtpConnect(LPFTPDATA pFtpData);
	
	BOOL FtpDownloadFile(const CString & strFilePath, const CString & strNewFile, BOOL bCreateDir = TRUE);
	BOOL FtpDownloadFile(const CString & strPath, const CString & strFileName, const CString & strNewFile);
	BOOL FtpDownloadFileEx(const CString & strRemotePath, const CString & strLocalFile, BOOL bCreateDirIfNotExist);

	BOOL FtpDownloadDir(const CString & strRemotePath, const CString & strLocalPath);
	BOOL FtpDownloadDirEx(const CString & strRemotePath, const CString & strLocalPath, DWORD dwFileType, SYSTEMTIME & time);
	BOOL FtpDownloadDirEx(LPDOWNLOADDATA pDownloadData);

	BOOL FtpGetFileList(const CString & strPath, vector<CString>& vFileList);

	BOOL FtpUploadFile(const CString & strRemotePath, const CString & strFilePath);

private:
	HINTERNET m_InternetSession;
	static CFtpConnection * m_pInstance;

};

#endif // !defined(AFX_FTPCONNECTION_H__A0BE133E_25DB_4ED0_9C73_32CE06064EEB__INCLUDED_)
